package br.com.napoleao.controlfin.form;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

import br.com.napoleao.controlfin.util.GUIUtil;
import com.swtdesigner.SWTResourceManager;

public class PrincipalShell {

	protected Shell shlControleFinanceiro;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			PrincipalShell window = new PrincipalShell();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		GUIUtil.centralizeShell(shlControleFinanceiro);
		shlControleFinanceiro.open();
		shlControleFinanceiro.layout();
		while (!shlControleFinanceiro.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shlControleFinanceiro = new Shell();
		shlControleFinanceiro.setImage(SWTResourceManager.getImage(PrincipalShell.class, "/br/com/napoleao/controlfin/form/resources/icone.png"));
		shlControleFinanceiro.setMinimumSize(new Point(1000, 650));
		shlControleFinanceiro.setSize(1000, 650);
		shlControleFinanceiro.setText("Controle Financeiro");
		
		Menu menu = new Menu(shlControleFinanceiro, SWT.BAR);
		shlControleFinanceiro.setMenuBar(menu);
		
		MenuItem mntmCadastros = new MenuItem(menu, SWT.CASCADE);
		mntmCadastros.setText("Cadastros");
		
		Menu menu_1 = new Menu(mntmCadastros);
		mntmCadastros.setMenu(menu_1);
		
		MenuItem mntmConta = new MenuItem(menu_1, SWT.NONE);
		mntmConta.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ManterContaDialog mcd = new ManterContaDialog(shlControleFinanceiro, SWT.DIALOG_TRIM);
				mcd.open();
			}
		});
		mntmConta.setText("Conta");
		
		MenuItem mntmCategoria = new MenuItem(menu_1, SWT.NONE);
		mntmCategoria.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ManterCategoriaDialog mcd = new ManterCategoriaDialog(shlControleFinanceiro, SWT.DIALOG_TRIM);
				mcd.open();
			}
		});
		mntmCategoria.setText("Categoria");
		
		MenuItem mntmPessoa = new MenuItem(menu_1, SWT.NONE);
		mntmPessoa.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ManterPessoaDialog mcd = new ManterPessoaDialog(shlControleFinanceiro, SWT.DIALOG_TRIM);
				mcd.open();
			}
		});
		mntmPessoa.setText("Pessoa");
		
		MenuItem mntmMovimentaes = new MenuItem(menu, SWT.CASCADE);
		mntmMovimentaes.setText("Movimenta\u00E7\u00F5es");
		
		Menu menu_2 = new Menu(mntmMovimentaes);
		mntmMovimentaes.setMenu(menu_2);
		
		MenuItem mntmRegistrar = new MenuItem(menu_2, SWT.NONE);
		mntmRegistrar.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				AdicionarMovDialog amd = new AdicionarMovDialog(shlControleFinanceiro, SWT.DIALOG_TRIM);
				amd.open();
			}
		});
		mntmRegistrar.setText("Registrar");
		
		MenuItem mntmControle = new MenuItem(menu_2, SWT.NONE);
		mntmControle.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				shlControleFinanceiro.setLayout(new FillLayout());
				new ControleMovShell(shlControleFinanceiro, SWT.NONE);
				shlControleFinanceiro.layout();		
			}
		});
		mntmControle.setText("Controle");

	}
}
